package com.lch.netty.netty.rpc.register;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author: liuchenhui
 * @create: 2019-10-20 13:58
 **/
public class RegisterHandler extends ChannelInboundHandlerAdapter {

    private List<String> classNames = new ArrayList<>();

    public RegisterHandler() {
        // 注册服务，将所有服务初始化成map存在本地
        scannerClass("com.lch.netty.netty.rpc.provider");
    }

    private void scannerClass(String packageName) {
        URL resource = this.getClass().getClassLoader().getResource(packageName.replaceAll("\\.", "/"));
        File filePath = new File(resource.getPath());
        File[] files = filePath.listFiles();
        for (File f : files) {
            if (f.isDirectory()){
                scannerClass(packageName + "." + f.getName());
            } else {
            }
        }
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        // 1、
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }
}
